﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Net.Sockets;

using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace QuanLyDiemDHBK
{
    public partial class QLDiemClient : Form
    {
        ConnectServer frmconnect = new ConnectServer();
        private static string ip = "";
        private static string titleReport = "", titleReport1 = "";
        byte[] receivedata = new byte[1024 * 5000];
        byte[] senddata = new byte[1024];
        static DataTable khoahoc, lop, hocky, khoa, monhoc;
        static DataTable diem, tichluy;
        static int kt = 0;
        public QLDiemClient()
        {
            InitializeComponent();
        }

        public object DeserializeData(byte[] theByteArray)
        {
            MemoryStream ms = new MemoryStream(theByteArray);
            BinaryFormatter bf1 = new BinaryFormatter();
            ms.Position = 0;
            return bf1.Deserialize(ms);
        }

        public byte[] SerializeData(Object o)
        {
            MemoryStream ms = new MemoryStream();
            BinaryFormatter bf1 = new BinaryFormatter();
            bf1.Serialize(ms, o);
            return ms.ToArray();
        }

        public Socket socket()
        {
            IPAddress[] ipAddress = Dns.GetHostAddresses(ip);

            IPEndPoint ipEnd = new IPEndPoint(ipAddress[0], 5656);
            Socket clientSock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            clientSock.Connect(ipEnd);
            return clientSock;
        }

        private void QLDiemClient_Load(object sender, EventArgs e)
        {
            ip = frmconnect.getip();
            Socket soc = socket();
            // nhan bang khoa
            senddata = SerializeData("khoa");
            soc.Send(senddata);
            soc.Receive(receivedata);
            khoa = new DataTable();
            khoa = (DataTable)DeserializeData(receivedata);
          
            int sohang = khoa.Rows.Count;
            int i = 0;
            comboBox1.Items.Add("Tất cả");
            while (i < sohang)
            {
                comboBox1.Items.Add(khoa.Rows[i][1]);
                i++;
            }
            soc.Close();
        }

        private void QLDiemClient_FormClosing(object sender, FormClosingEventArgs e)
        {
            frmconnect.Show();
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string tmpkhoa = comboBox1.Text;
            if (tmpkhoa == "Tất cả")
            {
                cbbkhoahoc.Text = "Tất cả";
                cbblop.Text = "Tất cả";
                cbbhocky.Text = "Tất cả";
            }
            Socket soc = socket();
            //nhan bang khoahoc
            senddata = SerializeData("khoahoc");
            soc.Send(senddata);
            soc.Receive(receivedata);
            khoahoc = new DataTable();
            khoahoc = (DataTable)DeserializeData(receivedata);
            cbbkhoahoc.Items.Clear();
            int sohang = khoahoc.Rows.Count;
            int i = 0;
            cbbkhoahoc.Items.Add("Tất cả");
            while (i < sohang)
            {
                cbbkhoahoc.Items.Add(khoahoc.Rows[i][1]);
                i++;
            }
            soc.Close();
        }

        private void cbbkhoahoc_SelectedIndexChanged(object sender, EventArgs e)
        {
            string idkhoa = getma(khoa, comboBox1.Text);
            string idkhoahoc = getma(khoahoc, cbbkhoahoc.Text);
            if (cbbkhoahoc.Text == "Tất cả")
            {
                cbblop.Text = "Tất cả";
                cbbhocky.Text = "Tất cả";
            }
            Socket soc = socket();
            // nhan bang lop
            senddata = SerializeData("lop");
            soc.Send(senddata);
            soc.Receive(receivedata);
            lop = new DataTable();
            lop = (DataTable)DeserializeData(receivedata);

            cbblop.Items.Clear();
            int sohang = lop.Rows.Count;
            int i = 0;
            cbblop.Items.Add("Tất cả");
            while (i < sohang)
            {
                string idk = (string)lop.Rows[i][2];
                string idkh = (string)lop.Rows[i][3];
                if (idk.Equals(idkhoa) && idkh.Equals(idkhoahoc))
                    cbblop.Items.Add(lop.Rows[i][1]);
                i++;
            }
            soc.Close();
        }

        private void cbblop_SelectedIndexChanged(object sender, EventArgs e)
        {
            Socket soc = socket();
            if (cbblop.Text == "Tất cả")
            {
                cbbhocky.Text = "Tất cả";
            }
            // nhan bang hocky
            senddata = SerializeData("hocky");
            soc.Send(senddata);
            soc.Receive(receivedata);
            hocky = new DataTable();
            hocky = (DataTable)DeserializeData(receivedata);
            cbbhocky.Items.Clear();
            int sohang = hocky.Rows.Count;
            int i = 0;
            cbbhocky.Items.Add("Tất cả");
            while (i < sohang)
            {
                cbbhocky.Items.Add(hocky.Rows[i][1]);
                i++;
            }
            soc.Close();
        }

        private string getma(DataTable dt, string temp)
        {
            int sohang = dt.Rows.Count;
            int i = 0;
            while (i < sohang)
            {
                string ten = (string)dt.Rows[i][1];
                if (temp.Equals(ten)) return (string)dt.Rows[i][0];
                i++;
            }
            return "";
        }

        private void btnxem_Click(object sender, EventArgs e)
        {
            Socket soc = socket();
            diem = new DataTable();
            string khoa = comboBox1.Text;
            string khoahoc = cbbkhoahoc.Text;
            string lop = cbblop.Text;
            string hocky = cbbhocky.Text;
            if (khoa.Equals("Tất cả"))
            {
                senddata = SerializeData("select STT,Diem.MaSV,HoTen,TenLop,TenMH,DiemCC,DiemGK,DiemCK,DiemChu,DiemPhay,MaHK from Lop,SinhVien,Diem,MonHoc " +
                    "where Diem.MaMH = MonHoc.MaMH and SinhVien.MaLop = Lop.MaLop and Diem.MaSV = SinhVien.MaSV order by MaSV,MaHK ASC");
                titleReport = "SINH VIÊN TOÀN TRƯỜNG";
            }
            else if (khoahoc.Equals("Tất cả") && lop.Equals("Tất cả") && hocky.Equals("Tất cả"))
            {
                senddata = SerializeData("select STT,Diem.MaSV,HoTen,TenLop,TenMH,DiemCC,DiemGK,DiemCK,DiemChu,DiemPhay,MaHK from Lop,SinhVien,Diem,MonHoc " +
                    "where Diem.MaMH = MonHoc.MaMH and SinhVien.MaLop = Lop.MaLop and Diem.MaSV = SinhVien.MaSV and Diem.MaSV in (select MaSV from SinhVien where MaLop in " +
                    "(select MaLop from Lop where MaKhoa = (select MaKhoa from Khoa where TenKhoa like N'" + khoa + "'))) order by MaSV,MaHK ASC");
                titleReport = "SINH VIÊN KHOA " + comboBox1.Text;
            }

            else if (lop.Equals("Tất cả") && hocky.Equals("Tất cả"))
            {
                senddata = SerializeData("select STT,Diem.MaSV,HoTen,TenLop,TenMH,DiemCC,DiemGK,DiemCK,DiemChu,DiemPhay,MaHK from Lop,SinhVien,Diem,MonHoc " +
                    "where Diem.MaMH = MonHoc.MaMH and SinhVien.MaLop = Lop.MaLop and Diem.MaSV = SinhVien.MaSV and Diem.MaSV in (select MaSV from SinhVien where MaLop in " +
                    "(select MaLop from Lop where MaKhoa = (select MaKhoa from Khoa where TenKhoa like N'" + khoa + "') and MaKhoaHoc = " +
                    "(select MaKhoaHoc from KhoaHoc where TenKhoaHoc like N'" + khoahoc + "'))) order by MaSV,MaHK ASC");
                titleReport = cbbkhoahoc.Text + " kHOA " + comboBox1.Text;
            }

            else if (hocky.Equals("Tất cả"))
            {
                senddata = SerializeData("select STT,Diem.MaSV,HoTen,TenLop,TenMH,DiemCC,DiemGK,DiemCK,DiemChu,DiemPhay,MaHK from Lop,SinhVien,Diem,MonHoc " +
                    "where Diem.MaMH = MonHoc.MaMH and SinhVien.MaLop = Lop.MaLop and Diem.MaSV = SinhVien.MaSV and Diem.MaSV in (select MaSV from SinhVien where MaLop in " +
                    "(select MaLop from Lop where MaKhoa = (select MaKhoa from Khoa where TenKhoa like N'" + khoa + "') and MaKhoaHoc = " +
                    "(select MaKhoaHoc from KhoaHoc where TenKhoaHoc like N'" + khoahoc + "') and TenLop like N'" + lop + "')) order by MaSV,MaHK ASC");
                titleReport = cbblop.Text + " kHOA " + comboBox1.Text;
            }

            else if (!khoahoc.Equals("Tất cả") && !lop.Equals("Tất cả") && !hocky.Equals("Tất cả"))
            {
                senddata = SerializeData("select STT,Diem.MaSV,HoTen,TenLop,TenMH,DiemCC,DiemGK,DiemCK,DiemChu,DiemPhay,MaHK from Lop,SinhVien,Diem,MonHoc " +
                    "where Diem.MaMH = MonHoc.MaMH and SinhVien.MaLop = Lop.MaLop and Diem.MaSV = SinhVien.MaSV and Diem.MaSV in (select MaSV from SinhVien where MaLop in " +
                    "(select MaLop from Lop where MaKhoa = (select MaKhoa from Khoa where TenKhoa like N'" + khoa + "') and MaKhoaHoc = " +
                    "(select MaKhoaHoc from KhoaHoc where TenKhoaHoc like N'" + khoahoc + "') and TenLop like N'" + lop + "'))" +
                    " and MaHK like (select MaHK from HocKy where TenHK like N'" + hocky + "') order by MaSV,MaHK ASC");
                titleReport = cbblop.Text + " kHOA " + comboBox1.Text + " " + cbbhocky.Text;
            }
          
            soc.Send(senddata);
            soc.Receive(receivedata);
            diem = (DataTable)DeserializeData(receivedata);
            dataGriview.DataSource = diem;

            btnthem.Enabled = true;
            btnsua.Enabled = true;
            btnxoa.Enabled = true;
            btnDiemtl.Enabled = true;
            btninbangdiem.Enabled = true;
            btndiemf.Enabled = true;
            btnphay.Enabled = true;
        }

        private void btnsearch_Click(object sender, EventArgs e)
        {
            Socket soc = socket();
            diem = new DataTable();
            string timkiem = tbtimkiem.Text;
            senddata = SerializeData("select STT,Diem.MaSV,HoTen,TenLop,TenMH,DiemCC,DiemGK,DiemCK,DiemChu,DiemPhay,MaHK from Lop,SinhVien,Diem,MonHoc " +
                    "where Diem.MaMH = MonHoc.MaMH and SinhVien.MaLop = Lop.MaLop and Diem.MaSV = SinhVien.MaSV and (Diem.MaSV = '" + timkiem + "' or Diem.MaSV = (select MaSV from SinhVien where HoTen like N'%" + timkiem + "%')) order by MaSV,MaHK ASC");
            titleReport = "SINH VIÊN";
            soc.Send(senddata);
            soc.Receive(receivedata);
            diem = (DataTable)DeserializeData(receivedata);
            dataGriview.DataSource = diem;

            btnthem.Enabled = true;
            btnsua.Enabled = true;
            btnxoa.Enabled = true;
            btnDiemtl.Enabled = true;
            btninbangdiem.Enabled = true;
            btndiemf.Enabled = true;
            btnphay.Enabled = true;
        }

        ThemThongTin frmthemthongtin = null;
        private void btnthem_Click(object sender, EventArgs e)
        {
            string masv = dataGriview.CurrentRow.Cells[1].Value.ToString();
            string tensv = dataGriview.CurrentRow.Cells[2].Value.ToString();
            string lopsv = dataGriview.CurrentRow.Cells[3].Value.ToString();
            Socket soc = socket();
            monhoc = new DataTable();
            senddata = SerializeData("select * from MonHoc");
            soc.Send(senddata);
            soc.Receive(receivedata);
            monhoc = (DataTable)DeserializeData(receivedata);

            if (MessageBox.Show("Bạn đã chọn sinh viên " + tensv + " để thêm thông tin" +
                "\n\tBẠN ĐỒNG Ý VỚI SỰ LỰA CHỌN CỦA BẠN..?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                frmthemthongtin = new ThemThongTin(masv, tensv, lopsv, monhoc);
                frmthemthongtin.ShowDialog();
                string sql = frmthemthongtin.getsql();
                if (!sql.Equals(""))
                {
                    Socket socinsert = socket();
                    senddata = SerializeData(sql);
                    socinsert.Send(senddata);
                    socinsert.Receive(receivedata);

                    MessageBox.Show((string)DeserializeData(receivedata));
                }
            }

        }

        SuaThongTin frmsuatt = null;
        private void btnsua_Click(object sender, EventArgs e)
        {
            string sttsv = dataGriview.CurrentRow.Cells[0].Value.ToString();
            string masv = dataGriview.CurrentRow.Cells[1].Value.ToString();
            string tensv = dataGriview.CurrentRow.Cells[2].Value.ToString();
            string lopsv = dataGriview.CurrentRow.Cells[3].Value.ToString();
            string monhoc = dataGriview.CurrentRow.Cells[4].Value.ToString();
            string diemcc = dataGriview.CurrentRow.Cells[5].Value.ToString();
            string diemgk = dataGriview.CurrentRow.Cells[6].Value.ToString();
            string diemck = dataGriview.CurrentRow.Cells[7].Value.ToString();
            string hocky = dataGriview.CurrentRow.Cells[10].Value.ToString();
            frmsuatt = new SuaThongTin(sttsv, masv, tensv, lopsv, monhoc, diemcc, diemgk, diemck, hocky);
            frmsuatt.ShowDialog();
            string sql = frmsuatt.getsql();
            if (!sql.Equals(""))
            {
                Socket socupdate = socket();
                senddata = SerializeData(sql);
                socupdate.Send(senddata);
                socupdate.Receive(receivedata);

                MessageBox.Show((string)DeserializeData(receivedata));
            }
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            Socket soc = socket();
            string sttsv = dataGriview.CurrentRow.Cells[0].Value.ToString();
            if (MessageBox.Show("Bạn có chắc muốn xóa không..?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                senddata = SerializeData("delete from Diem where STT = '" + sttsv + "'");
                soc.Send(senddata);
                dataGriview.Rows.RemoveAt(dataGriview.CurrentRow.Index);
                soc.Receive(receivedata);
                MessageBox.Show((string)DeserializeData(receivedata));
            }
            
        }

        private void btninbangdiem_Click(object sender, EventArgs e)
        {
            
            DataTable dt = (DataTable)dataGriview.DataSource;
            if (kt == 0)
            {
                ExportToExcel reportexcel = new ExportToExcel();
                reportexcel.Export(dt, "Bang diem", "BẢNG ĐIỂM " + titleReport.ToUpper());
            }
            else if(kt ==1 )
            {
                ExportToExcelTL reportexcel = new ExportToExcelTL();
                reportexcel.Export(dt, "Bang diem", titleReport1.ToUpper() + " " + titleReport.ToUpper());
            }
            else
            {
                ExportToExcel reportexcel = new ExportToExcel();
                reportexcel.Export(dt, "Bang diem", titleReport1.ToUpper() + " " + titleReport.ToUpper());
            }
            kt = 0;
        }

        private void btnDiemtl_Click(object sender, EventArgs e)
        {
            string masv = "", hocky = "";
            int sohang = diem.Rows.Count;
            int i = 0, k = 0;
            float diemtbh4 = 0, diemtbh10 = 0;
            int tcdh = 0, smcd = 0, stt = 0;

            Socket soc = socket();
            monhoc = new DataTable();
            senddata = SerializeData("select * from MonHoc");
            soc.Send(senddata);
            soc.Receive(receivedata);
            monhoc = (DataTable)DeserializeData(receivedata);
            int tongmonhoc = monhoc.Rows.Count;

            tichluy = new DataTable();
            tichluy.Columns.Add(new DataColumn("STT"));
            tichluy.Columns.Add(new DataColumn("Mã SV"));
            tichluy.Columns.Add(new DataColumn("Tên SV"));
            tichluy.Columns.Add(new DataColumn("Lớp"));
            tichluy.Columns.Add(new DataColumn("TB Hệ 4"));
            tichluy.Columns.Add(new DataColumn("TB Hệ 10"));
            tichluy.Columns.Add(new DataColumn("Số TC đã học"));
            tichluy.Columns.Add(new DataColumn("Số môn chưa đạt"));
            tichluy.Columns.Add(new DataColumn("Học kỳ"));
            DataRow tichluyrows;
            tichluyrows = tichluy.NewRow();

            while (i < sohang)
            {
                masv = (string)diem.Rows[i][1];
                hocky = (string)diem.Rows[i][10];


                if (i != 0) k = i - 1;
                if (!masv.Equals((string)diem.Rows[k][1]) || !hocky.Equals((string)diem.Rows[k][10]))
                {
                    diemtbh4 = diemtbh4 / tcdh;
                    diemtbh10 = diemtbh10 / tcdh;
                    tichluyrows[0] = stt;
                    tichluyrows[1] = diem.Rows[k][1];
                    tichluyrows[2] = diem.Rows[k][2];
                    tichluyrows[3] = diem.Rows[k][3];
                    tichluyrows[4] = diemtbh4;
                    tichluyrows[5] = diemtbh10;
                    tichluyrows[6] = tcdh;
                    tichluyrows[7] = smcd;
                    tichluyrows[8] = diem.Rows[k][10];

                    tichluy.Rows.Add(tichluyrows);
                    tichluyrows = tichluy.NewRow();

                    diemtbh4 = 0; diemtbh10 = 0;
                    tcdh = 0; smcd = 0;
                    stt++;

                    int j = 0;
                    while (!diem.Rows[i][4].Equals(monhoc.Rows[j][1]) && j <= tongmonhoc) j++;
                    diemtbh10 = (float)(diemtbh10 + (int)monhoc.Rows[j][2] * (double)diem.Rows[i][9]);

                    if (diem.Rows[i][8].Equals("A         "))
                    {
                        diemtbh4 = diemtbh4 + 4 * (int)monhoc.Rows[j][2]; tcdh = tcdh + (int)monhoc.Rows[j][2];
                    }
                    else if (diem.Rows[i][8].Equals("B         "))
                    {
                        diemtbh4 = diemtbh4 + 3 * (int)monhoc.Rows[j][2]; tcdh = tcdh + (int)monhoc.Rows[j][2];
                    }
                    else if (diem.Rows[i][8].Equals("C         "))
                    {
                        diemtbh4 = diemtbh4 + 2 * (int)monhoc.Rows[j][2]; tcdh = tcdh + (int)monhoc.Rows[j][2];
                    }
                    else if (diem.Rows[i][8].Equals("D         "))
                    {
                        diemtbh4 = diemtbh4 + 1 * (int)monhoc.Rows[j][2]; tcdh = tcdh + (int)monhoc.Rows[j][2];
                    }
                    else { smcd++; tcdh = tcdh + (int)monhoc.Rows[j][2]; diemtbh4 = diemtbh4 + 0; }

                }
                else
                {
                    int j = 0;
                    while (!diem.Rows[i][4].Equals(monhoc.Rows[j][1]) && j <= tongmonhoc) j++;
                    diemtbh10 = (float)(diemtbh10 + (int)monhoc.Rows[j][2] * (double)diem.Rows[i][9]);

                    if (diem.Rows[i][8].Equals("A         "))
                    {
                        diemtbh4 = diemtbh4 + 4 * (int)monhoc.Rows[j][2]; tcdh = tcdh + (int)monhoc.Rows[j][2];
                    }
                    else if (diem.Rows[i][8].Equals("B         "))
                    {
                        diemtbh4 = diemtbh4 + 3 * (int)monhoc.Rows[j][2]; tcdh = tcdh + (int)monhoc.Rows[j][2];
                    }
                    else if (diem.Rows[i][8].Equals("C         "))
                    {
                        diemtbh4 = diemtbh4 + 2 * (int)monhoc.Rows[j][2]; tcdh = tcdh + (int)monhoc.Rows[j][2];
                    }
                    else if (diem.Rows[i][8].Equals("D         "))
                    {
                        diemtbh4 = diemtbh4 + 1 * (int)monhoc.Rows[j][2]; tcdh = tcdh + (int)monhoc.Rows[j][2];
                    }
                    else { smcd++; tcdh = tcdh + (int)monhoc.Rows[j][2]; diemtbh4 = diemtbh4 + 0; }
                }

                i++;
            }
            diemtbh4 = diemtbh4 / tcdh;
            diemtbh10 = diemtbh10 / tcdh;
            tichluyrows[0] = stt;
            tichluyrows[1] = diem.Rows[k][1];
            tichluyrows[2] = diem.Rows[k][2];
            tichluyrows[3] = diem.Rows[k][3];
            tichluyrows[4] = diemtbh4;
            tichluyrows[5] = diemtbh10;
            tichluyrows[6] = tcdh;
            tichluyrows[7] = smcd;
            tichluyrows[8] = diem.Rows[k][10];

            tichluy.Rows.Add(tichluyrows);

            kt = 1;
            titleReport1 = "Điểm tích lũy của ";
            dataGriview.DataSource = tichluy;
        }

        private void btndiemf_Click(object sender, EventArgs e)
        {
            DataTable diemf = new DataTable();
            DataRow diemfrows;
            diemf.Columns.Add(new DataColumn("STT"));
            diemf.Columns.Add(new DataColumn("Mã SV"));
            diemf.Columns.Add(new DataColumn("Tên SV"));
            diemf.Columns.Add(new DataColumn("Lớp"));
            diemf.Columns.Add(new DataColumn("Môn học"));
            diemf.Columns.Add(new DataColumn("Điểm chuyên cần"));
            diemf.Columns.Add(new DataColumn("Điểm giữa kỳ"));
            diemf.Columns.Add(new DataColumn("Điểm cuối kỳ"));
            diemf.Columns.Add(new DataColumn("Điểm F"));
            diemf.Columns.Add(new DataColumn("Điểm hệ 10"));
            diemf.Columns.Add(new DataColumn("Học kỳ"));

            int sohang = diem.Rows.Count;
            int i = 0;
            while (i < sohang)
            {
                if (diem.Rows[i][8].Equals("F         "))
                {
                    int k = 0;
                    diemfrows = diemf.NewRow();
                    while(k < 11)
                    {
                        diemfrows[k] = diem.Rows[i][k];
                        k++;
                    }
                    diemf.Rows.Add(diemfrows);
                }

                i++;
            }
            kt = 2;
            titleReport1 = "Danh sách sinh viên bị điểm F của";
            dataGriview.DataSource = diemf;
        }

        private void btnphay_Click(object sender, EventArgs e)
        {
            DataTable diemphay = new DataTable();
            DataRow diemphayrows;
            diemphay.Columns.Add(new DataColumn("STT"));
            diemphay.Columns.Add(new DataColumn("Mã SV"));
            diemphay.Columns.Add(new DataColumn("Tên SV"));
            diemphay.Columns.Add(new DataColumn("Lớp"));
            diemphay.Columns.Add(new DataColumn("Môn học"));
            diemphay.Columns.Add(new DataColumn("Điểm chuyên cần"));
            diemphay.Columns.Add(new DataColumn("Điểm giữa kỳ"));
            diemphay.Columns.Add(new DataColumn("Điểm cuối kỳ"));
            diemphay.Columns.Add(new DataColumn("Điểm F"));
            diemphay.Columns.Add(new DataColumn("Điểm hệ 10"));
            diemphay.Columns.Add(new DataColumn("Học kỳ"));

            int sohang = diem.Rows.Count;
            int i = 0;
            double ghdiem = Convert.ToDouble(tbghdiem.Text);

            while (i < sohang)
            {
                if (Convert.ToDouble(diem.Rows[i][9]) > ghdiem)
                {
                    int k = 0;
                    diemphayrows = diemphay.NewRow();
                    while (k < 11)
                    {
                        diemphayrows[k] = diem.Rows[i][k];
                        k++;
                    }
                    diemphay.Rows.Add(diemphayrows);
                }

                i++;
            }
            kt = 2;
            titleReport1 = "danh sách tổng phẩy lớn hơn " + tbghdiem.Text + " của";
            dataGriview.DataSource = diemphay;
        }

        private void tbghdiem_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !(e.KeyChar >= 48 && e.KeyChar <= 57 || e.KeyChar == 8 || e.KeyChar == 46);
        }
    }
}
